import { PriorityQueue } from "../util/Util";

//659. 分割数组为连续子序列
function isPossible(nums: number[]): boolean {
    let map = new Map<number,PriorityQueue<number>>()
    for(let x of nums){
        let len = 1
        if(map.has(x-1)){
            const que = map.get(x-1)!
            const min = que.poll()!
            if(que.isEmpty()) map.delete(x-1)
            len = min+1
        }
        if(!map.has(x)) {
            const que = new PriorityQueue<number>((a,b)=>a-b)
            map.set(x,que)
        }
        const que = map.get(x)!
        que.add(len)
        map.set(x,que)
    }
    for(let [k,v] of map){
        if(v.peek()!<3) return false
    }
    return true
};